package com.zpark.controller;

import com.zpark.entity.patients.WesternDiagnosisRecords;
import com.zpark.service.WesternDiagnosisRecordsService;
import com.zpark.utils.ResultVO;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/api/diagnosis-records")
public class WesternDiagnosisRecordsController {

    private final WesternDiagnosisRecordsService recordsService;

    public WesternDiagnosisRecordsController(WesternDiagnosisRecordsService recordsService) {
        this.recordsService = recordsService;
    }

    @GetMapping("/all")
    public ResultVO<List<WesternDiagnosisRecords>> getAllRecords() {
        List<WesternDiagnosisRecords> records = recordsService.getAllRecords();
        return ResultVO.success(records);
    }

    @GetMapping("/patient/{patientId}")
    public ResultVO<List<WesternDiagnosisRecords>> getRecordsByPatientId(@PathVariable Long patientId) {
        List<WesternDiagnosisRecords> records = recordsService.getRecordsByPatientId(patientId);
        return ResultVO.success(records);
    }

    @GetMapping("/{id}")
    public ResultVO<? extends Serializable> getRecordById(@PathVariable Long id) {
        WesternDiagnosisRecords record = recordsService.getById(id);
        return record != null ? ResultVO.success(record) : ResultVO.error(404,"记录不存在");
    }
}